package com.cx.service.impl;

import com.cx.dao.UserMapper;
import com.cx.pojo.User;
import com.cx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    @Qualifier("userMapper")
    private UserMapper userMapper;

    @Override
    //    查询所有用户以及管理的角色
    public List<User> getAllUser(Integer currentPage, Integer pageSize){
        int start = (currentPage - 1) * pageSize;

        List<User> list = userMapper.getAllUser(start, pageSize);
        return list;
    }

    //    查询总记录数
    public int count(){
        return userMapper.count();
    }

    @Override
    public User login(User user) {
        return userMapper.login(user);
    }

    @Override
    public void deleteUserById(Integer id) {
        userMapper.deleteUserById(id);
    }

    @Override
    public boolean myCheck(String name) {
        boolean flag = false;
        User user = userMapper.checkName(name);
        if (user != null) {
            flag = true;
        }
        return flag;
    }

//    添加用户
    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }

//    根据id查询指定的用户信息
    @Override
    public User getUserById(Integer id) {
        return userMapper.getUserById(id);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }


}
